package com.jeethink.erp.saleDetail.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jeethink.common.annotation.Log;
import com.jeethink.common.core.controller.BaseController;
import com.jeethink.common.core.domain.AjaxResult;
import com.jeethink.common.enums.BusinessType;
import com.jeethink.erp.saleDetail.domain.TbSaleDetail;
import com.jeethink.erp.saleDetail.service.ITbSaleDetailService;
import com.jeethink.common.utils.poi.ExcelUtil;
import com.jeethink.common.core.page.TableDataInfo;

/**
 * 销售明细Controller
 * 
 * @author ypr
 * @date 2021-06-07
 */
@RestController
@RequestMapping("/erp/saleDetail")
public class TbSaleDetailController extends BaseController
{
    @Autowired
    private ITbSaleDetailService tbSaleDetailService;

    /**
     * 查询销售明细列表
     */
    @PreAuthorize("@ss.hasPermi('erp:saleDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbSaleDetail tbSaleDetail)
    {
        startPage();
        List<TbSaleDetail> list = tbSaleDetailService.selectTbSaleDetailList(tbSaleDetail);
        return getDataTable(list);
    }

    /**
     * 导出销售明细列表
     */
    @PreAuthorize("@ss.hasPermi('erp:saleDetail:export')")
    @Log(title = "销售明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbSaleDetail tbSaleDetail)
    {
        List<TbSaleDetail> list = tbSaleDetailService.selectTbSaleDetailList(tbSaleDetail);
        ExcelUtil<TbSaleDetail> util = new ExcelUtil<TbSaleDetail>(TbSaleDetail.class);
        return util.exportExcel(list, "saleDetail");
    }

    /**
     * 获取销售明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:saleDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbSaleDetailService.selectTbSaleDetailById(id));
    }

    /**
     * 新增销售明细
     */
    @PreAuthorize("@ss.hasPermi('erp:saleDetail:add')")
    @Log(title = "销售明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbSaleDetail tbSaleDetail)
    {
        return toAjax(tbSaleDetailService.insertTbSaleDetail(tbSaleDetail));
    }

    /**
     * 修改销售明细
     */
    @PreAuthorize("@ss.hasPermi('erp:saleDetail:edit')")
    @Log(title = "销售明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbSaleDetail tbSaleDetail)
    {
        return toAjax(tbSaleDetailService.updateTbSaleDetail(tbSaleDetail));
    }

    /**
     * 删除销售明细
     */
    @PreAuthorize("@ss.hasPermi('erp:saleDetail:remove')")
    @Log(title = "销售明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbSaleDetailService.deleteTbSaleDetailByIds(ids));
    }
}
